﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_ListBasicReferences')
	BEGIN
		DROP  Procedure  [esf_sso].P_ListBasicReferences
	END

GO


CREATE Procedure [esf_sso].P_ListBasicReferences
	@pBasicReferenceTypeID	INT = NULL
	,@pBasicReferenceTypeIDs VARCHAR (MAX) = NULL
	,@pPartName				VARCHAR (60) = NULL
	,@pListCount			INT = NULL
	,@pIsEnabled			BIT = NULL
AS

	SET NOCOUNT ON
	
	
	IF @pListCount IS NOT NULL
	BEGIN
		SET ROWCOUNT @pListCount
	END
	
	SELECT
		VBR.ID
		,VBR.Code
		,VBR.Name
		,VBR.Extra_I
		,VBR.Extra_II
		,VBR.Extra_III
	FROM
		esf_sso.VBasicReference VBR
	WHERE
		(@pBasicReferenceTypeID IS NULL OR VBR.BasicReferenceTypeID = @pBasicReferenceTypeID)
		AND (@pBasicReferenceTypeIDs IS NULL OR VBR.BasicReferenceTypeID IN (SELECT TempItem FROM [dbo].[FUBSplitString] (@pBasicReferenceTypeIDs, ',')))
		AND (@pPartName IS NULL OR VBR.Name LIKE @pPartName)
		AND (@pIsEnabled IS NULL OR VBR.IsEnabled = @pIsEnabled)
	ORDER BY
		VBR.Name

GO